<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('直播列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>直播名称：</label>
                                <input type="text" name="VideoName"/>
                            </li>
                            <li class="select-time">
                                <label>开始时间：</label>
                                <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="StartTime"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="EndTime"/>
                            </li>
                            <li>
                                操作人员：<input type="text" name="createBy"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:video:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:video:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:video:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:video:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:video:remove')}]];
        var prefix = ctx + "system/video";

        function zb(id,startTime,endTime){
            var starttime = new Date(Date.parse(startTime));
            var endtime = new Date(Date.parse(endTime));
            var nowdate = new Date();
            if (starttime>nowdate){
                $.modal.alert("未到直播时间!");
            }
            else if (nowdate>endtime){
                $.modal.alert("直播已结束!");
            }
            else  {
                window.open(prefix+"/Livebroadcast");
            }
            // alert("id为："+id+"创建者为："+startTime+"-"+endTime);

        }

        function replay(id,startTime,endTime){
            var url = "/toReplay?StartTime="+startTime+"&EndTime="+endTime;
            var starttime = new Date(Date.parse(startTime));
            var endtime = new Date(Date.parse(endTime));
            var nowdate = new Date();
            if (starttime>nowdate){
                $.modal.alert("直播未开始!");
            }
            else if (nowdate>endtime){
                window.open(prefix+url);
            }else {
                $.modal.alert("直播进行中!");
            }
        }

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                modalName: "直播",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'videoId',
                    title: '直播id',
                    visible: false
                },
                    {
                        field: 'videoName',
                        title: '直播名称'
                    },
                {
                    field: 'rtmpsmoothAddress',
                    title: '网页端流畅直播地址',
                    visible: false
                },
                {
                    field: 'rtmphdaddress',
                    title: '网页端高清直播地址',
                    visible: false
                },
                {
                    field: 'hlssmoothAddress',
                    title: '移动端流畅直播地址',
                    visible: false
                },
                {
                    field: 'hlshdaddress',
                    title: '移动端高清直播地址',
                    visible: false
                },
                {
                    field: 'startTime',
                    title: '直播开始时间'
                },
                {
                    field: 'endTime',
                    title: '直播结束时间'
                },
                {
                    field: 'imgurl',
                    title: '封面图片',
                    formatter: function(value, row, index) {
                        return $.table.imageView(value);
                    }
                    // field: 'imgurl',
                    // title: '封面图片url'
                },
                {
                    field: 'title',
                    title: '简介'
                },
                {
                    field: 'localVideo',
                    title: '本地录像',
                    visible: false
                },
                {
                    field: 'cloudVideo',
                    title: '云存储录像',
                    visible: false
                },{
                        field : 'createBy',
                        title : '创建者'
                    },
                    {
                        field: 'createTime',
                        title: '创建时间',
                        sortable: true
                    },
                    {
                        field : 'updateBy',
                        title : '更新人'
                    },
                    {
                        field: 'updateTime',
                        title: '更新时间',
                        sortable: true
                    },
                    {
                        title: '设备',
                        align: 'center',
                        formatter: function (value, row, index) {
                            var actions = [];
                            actions.push('<a class="btn btn-default  dim " style="margin-left: 10px;" onclick="zb(\'' + row.videoId + '\',\'' + row.startTime + '\',\'' + row.endTime + '\')"><i>直播</i></a>');
                            actions.push('<a class="btn btn-default  dim " style="margin-left: 10px;" onclick="replay(\'' + row.videoId + '\',\'' + row.startTime + '\',\'' + row.endTime + '\')"><i>回放</i></a>');
                            return actions.join('');
                        }
                    },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.videoId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.videoId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
    </script>
</body>
</html>